package bad;

import java.util.Scanner;

public class SomeTopic {
    public static void debug(Object o){
        String s = "Thread : "+Thread.currentThread().getName();
        System.out.println(s+" o: "+o.toString());
    }

    public static void main(String[] args) {

        content();
    }

    public static void content(){
        String lock = "lock";
        debug("初始化线程已经启动");
        new Thread(()->{
            debug("案发线程已经启动");

            int k =0;
            while (true){
                k+=1;
                debug(String.format("第%02d轮作案开始", k));

                try {
                    synchronized (lock){
                        System.out.println("=========作案>>>>>>");
                        Thread.sleep(1000);
                        System.out.println("=========忏悔>>>>>>");
                        lock.wait();
                        debug(String.format("第%02d轮作案结束", k));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }



            }

        },"案发").start();
        new Thread(()->{
            debug("隐蔽线程已经启动");
            int j =0;
            while (true){
                j+=1;
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                debug("隐蔽线程第"+j+"次工作");
                synchronized (lock){
                    debug("隐蔽线程第"+j+"次工作");
                    lock.notify();
                    debug("隐蔽线程第"+j+"次工作");
                }
            }
        },"隐蔽").start();
        debug("初始化线程已经结束");
    }
}
